package com.ruoyi.source.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.source.domain.PackType;
import com.ruoyi.source.service.IPackTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 包装类型Controller
 * 
 * @author ruoyi
 * @date 2025-01-03
 */
@RestController
@RequestMapping("/source/packType")
public class PackTypeController extends BaseController
{
    @Autowired
    private IPackTypeService packTypeService;

    /**
     * 查询包装类型列表
     */
    @PreAuthorize("@ss.hasPermi('source:packType:list')")
    @GetMapping("/list")
    public TableDataInfo list(PackType packType)
    {
        startPage();
        List<PackType> list = packTypeService.selectPackTypeList(packType);
        return getDataTable(list);
    }

    /**
     * 导出包装类型列表
     */
    @PreAuthorize("@ss.hasPermi('source:packType:export')")
    @Log(title = "包装类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PackType packType)
    {
        List<PackType> list = packTypeService.selectPackTypeList(packType);
        ExcelUtil<PackType> util = new ExcelUtil<PackType>(PackType.class);
        util.exportExcel(response, list, "包装类型数据");
    }

    /**
     * 获取包装类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('source:packType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(packTypeService.selectPackTypeById(id));
    }

    /**
     * 新增包装类型
     */
    @PreAuthorize("@ss.hasPermi('source:packType:add')")
    @Log(title = "包装类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PackType packType)
    {
        return toAjax(packTypeService.insertPackType(packType));
    }

    /**
     * 修改包装类型
     */
    @PreAuthorize("@ss.hasPermi('source:packType:edit')")
    @Log(title = "包装类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PackType packType)
    {
        return toAjax(packTypeService.updatePackType(packType));
    }

    /**
     * 删除包装类型
     */
    @PreAuthorize("@ss.hasPermi('source:packType:remove')")
    @Log(title = "包装类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(packTypeService.deletePackTypeByIds(ids));
    }
}
